package com.zzy.bridge;

import com.zzy.pojo.UserInfo;
import com.zzy.repo.UserRepository;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @Author: zzy
 * @CreateTime: 2024-09-30
 * @Description: 注册登录函数接口抽象类
 * @Version: 1.0
 */
public abstract class AbstractRegisterLoginFunc implements RegisterLoginFuncInterface {

    public String commonLogin(String account, String password, UserRepository userRepository) {
        UserInfo userInfo = userRepository.findByUserNameAndUserPassword(account, password);
        if (userInfo == null) {
            return "用户名或密码错误";
        }
        return "登录成功";
    }

    public String commonRegister(UserInfo userInfo, UserRepository userRepository) {
        if (checkUserExist(userInfo.getUserName())) {
            return "用户已存在";
        }
        userInfo.setCreateDate(new Date());
        userRepository.save(userInfo);
        return "注册成功";
    }

    public boolean commonCheckUserExist(String userName, UserRepository userRepository) {
        UserInfo userInfo = userRepository.findByUserName(userName);
        if (userInfo == null) {
            return false;
        }
        return true;
    }

    @Override
    public String login(String account, String password) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String register(UserInfo userInfo) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean checkUserExist(String userName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String login3rd(HttpServletRequest request) {
        throw new UnsupportedOperationException();
    }
}
